<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateUserPackBagsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('user_pack_bags', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->default(0)->comment('用户ID');
            $table->unsignedSmallInteger('gift_id')->default(0)->comment('礼物ID');
            $table->tinyInteger('flag')->default(0)->comment('状态：0-待使用，1-已使用');
            $table->timestamp('used_at', 1)->nullable()->comment('使用时间');
            $table->timestamps();
            $table->index('user_id', 'user_id');
            $table->index('gift_id', 'gift_id');
            $table->index(['user_id', 'gift_id', 'flag'], 'user_gift_flag');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('user_pack_bags');
    }
}
